package com.wxyzz.canteenadmin.shop.shopList.controller;

import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.shop.shopList.VO.ShopVO;
import com.wxyzz.canteenadmin.shop.shopList.param.ShopAddParam;
import com.wxyzz.canteenadmin.shop.shopList.param.ShopListPageParam;
import com.wxyzz.canteenadmin.shop.shopList.service.ShopListService;
import com.wxyzz.canteencommon.common.R;
import com.wxyzz.canteencommon.entity.shop.shopList.ShopList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/10/10
 * @Solgne 从想做到能做
 * @Desc
 */
@RestController
@RequestMapping("/shop/shopList")
public class ShopListServiceController {
    @Autowired
    private ShopListService shopListService;

    //分页和模糊查询
    @GetMapping("/page")
    public R page (ShopListPageParam shopListPageParam) {
        PageInfo<ShopList> shopListPageInfo = shopListService.page(shopListPageParam);
        return R.ok(shopListPageInfo);
    }

    //根据id查询
    @GetMapping("/shopInfo")
    public R findById (Integer id) {
        ShopList shop = shopListService.findById(id);
        return R.ok(shop);
    }

    //根据id删除
    @GetMapping("/del")
    public R delById (Integer id) {
        shopListService.deleteById(id);
        return R.ok();
    }

    //根据id删除
    @GetMapping("/delBatch")
    public R delBatch (@RequestParam("ids") List<Integer> ids) {
        shopListService.deleteBatch(ids);
        return R.ok();
    }

    //添加
    @PostMapping("/add")
    public R add (@RequestBody ShopAddParam shopAddParam) {
        shopListService.addShop(shopAddParam);
        return R.ok();
    }

    //根据id更新
    @PostMapping("/update")
    public R update (@RequestBody ShopList shopList) {
        System.out.println(shopList);
        shopListService.updateById(shopList);
        return R.ok();
    }

    @GetMapping("/shops")
    public R shops () {
        List<ShopVO> shops = shopListService.findShops();
        return R.ok(shops);
    }
}
